package org.alvin;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

public class EasyExcelDemo {


    public static void main(String[] args) {
//        OutputStream out = getOutputStream(fileName, response);
//        ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(out, clazz).excelType(ExcelTypeEnum.XLSX).registerWriteHandler(getDefaultHorizontalCellStyleStrategy());
//        ExcelWriter excelWriter = excelWriterBuilder.build();
//        ExcelWriterSheetBuilder excelWriterSheetBuilder;
//        WriteSheet writeSheet;
//        for (int i =1;i<=lists.size();i++){
//            excelWriterSheetBuilder = new ExcelWriterSheetBuilder(excelWriter);
//            excelWriterSheetBuilder.sheetNo(i);
//            excelWriterSheetBuilder.sheetName("sheet"+i);
//            writeSheet = excelWriterSheetBuilder.build();
//            excelWriter.write(lists.get(i-1),writeSheet);
//        }
//        out.flush();
//        excelWriter.finish();
//        out.close();

//        try {
//            response.setContentType("application/vnd.ms-excel");
//            response.setCharacterEncoding("utf-8");
//            ClassPathResource classPathResource = new ClassPathResource("/templates/VLRRSummary.xlsx");
//            InputStream fileInputStream = classPathResource.getInputStream();
//            ByteArrayOutputStream bos = new ByteArrayOutputStream();
//            XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream);
//            workbook.setSheetName(0, "sheetName");
//            for (String key : map.keySet()) {
//                workbook.cloneSheet(0, key);
//            }
//            workbook.removeSheetAt(0);
//            //写到流里
//            workbook.write(bos);
//            byte[] bArray = bos.toByteArray();
//            InputStream is = new ByteArrayInputStream(bArray);
//            //输出文件路径
//            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(is).build();
//            for (String key : map.keySet()) {
//                WriteSheet writeSheet = EasyExcel.writerSheet(key).build();
//                excelWriter.fill( map.get(key), writeSheet);
//            }
//            // 关闭流
//            excelWriter.finish();
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }
}
